/*
 * @Author: your name
 * @Date: 2021-08-26 14:08:50
 * @LastEditTime: 2021-08-26 14:16:25
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \orderSystems\src\excel\exportExcel.js
 */
import Vue from 'vue'
import axios from "../http/axios.js";
Vue.prototype.axios = axios;
// 导出
export default {
  exportMethod(data) {
      axios({
          method: data.method,
          url: data.url,
          data: data.data,
          responseType: 'blob',
          headers: {
              'Content-Type': 'application/json'
          }
      }).then((res) => {
          const link = document.createElement('a')
          let blob = new Blob([res.data], {
              type: 'application/vnd.ms-excel'
          })
          link.style.display = 'none'
          link.href = URL.createObjectURL(blob)

          link.download = data.fileName + '.xls' //下载的文件名  注意：加.xls是兼容火狐浏览器
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link)
      }).catch(error => {
          console.log(error)
      })
  }
}

